package cn.source.framework.web.service;

import cn.source.common.constant.UserConstants;
import cn.source.common.utils.StringUtils;
import cn.source.system.domain.SysCompany;
import cn.source.system.service.ISysCompanyService;
import cn.source.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 注册校验方法
 *
 * @author ruoyi
 */
@Component
public class SysRegisterService {
    @Autowired private ISysUserService userService;

    @Autowired private ISysCompanyService sysCompanyService;

    /** 企业注册 */
    public String register(SysCompany sysCompany) {
        String msg = "";
        if (StringUtils.isEmpty(sysCompany.getUserName())) {
            msg = "用户名不能为空";
        } else if (StringUtils.isEmpty(sysCompany.getPassword())) {
            msg = "用户密码不能为空";
        } else if (UserConstants.NOT_UNIQUE.equals(
                userService.checkUserNameUnique(sysCompany.getUserName()))) {
            msg = "注册账号 '" + sysCompany.getUserName() + "' 失败，该账号不可用，请修改管理员账号";
        } else {
            sysCompanyService.insertSysCompany(sysCompany);
        }
        return msg;
    }
}
